package com.meitianhui.convenitenbuy.widget.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.meitianhui.convenitenbuy.Constants;
import com.meitianhui.convenitenbuy.R;

/**
 * Created by amy on 2017/11/11.
 */

public class ShareDialog extends Dialog implements View.OnClickListener {

    private Context mContext;
    private OnShareClickListener mListener;
    private TextView mBtnShareWeiXinFriend;
    private TextView mBtnShareFriendCircle;
    private TextView mBtnShareQqFriend;
    private TextView mBtnShareQqZone;
    private TextView mBtnShareCancel, mBtnShareWxMini;
    private String shareType;

    public ShareDialog(@NonNull Context context,
                       OnShareClickListener listener, String typeOfShare) {
        super(context, R.style.dialog_with_alpha);
        this.mContext = context;
        this.mListener = listener;
        this.shareType = typeOfShare;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_share);
        try {
            Window window = this.getWindow();
            WindowManager.LayoutParams lp = window.getAttributes();
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
            window.setAttributes(lp);
            window.setGravity(Gravity.BOTTOM);
        } catch (Exception e) {
            e.printStackTrace();
        }
        // window.setWindowAnimations(R.style.Umengstyle);
        setCancelable(true);
        this.setCanceledOnTouchOutside(true);

        initView();
        initListener();
    }

    private void initListener() {
        mBtnShareQqFriend.setOnClickListener(this);
        mBtnShareQqZone.setOnClickListener(this);
        mBtnShareFriendCircle.setOnClickListener(this);
        mBtnShareWeiXinFriend.setOnClickListener(this);
        mBtnShareCancel.setOnClickListener(this);
        mBtnShareWxMini.setOnClickListener(this);
    }

    private void initView() {
        mBtnShareCancel = (TextView) findViewById(R.id.btn_share_cancle);
        mBtnShareWeiXinFriend = (TextView) findViewById(R.id.btn_sahre_weixin_friend);
        mBtnShareFriendCircle = (TextView) findViewById(R.id.btn_share_friendcircle);
        mBtnShareQqZone = (TextView) findViewById(R.id.btn_share_qq_zone);
        mBtnShareQqFriend = (TextView) findViewById(R.id.btn_share_qq_friend);
        mBtnShareWxMini = (TextView) findViewById(R.id.btn_share_wx_mini);
        if (shareType.equals(Constants.TYPE_GOOD_DETAIL_PAGE)){
            //如果是详情页面过来就显示小程序分享
            mBtnShareWxMini.setVisibility(View.VISIBLE);
            mBtnShareWeiXinFriend.setVisibility(View.GONE);

        }else {
            mBtnShareWxMini.setVisibility(View.GONE);
            mBtnShareWeiXinFriend.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_share_cancle:
                //取消
                this.dismiss();
                break;
            case R.id.btn_sahre_weixin_friend:
                //if (SystemUtils.isWXAppInstalledAndSupported())
                //微信好友
                mListener.WeChatFriends(v);
                break;
            case R.id.btn_share_friendcircle:
                //微信朋友圈
                mListener.FriendCircle(v);
                break;
            case R.id.btn_share_qq_zone:
                //qq空间
                mListener.QQZone(v);
                break;
            case R.id.btn_share_qq_friend:
                //QQ好友分享
                mListener.QQFriends(v);
                break;
            case R.id.btn_share_wx_mini:
                //小程序分享
                mListener.WxMini(v);
                break;
        }
    }

    public interface OnShareClickListener {

        /** 微信朋友圈 */
        void FriendCircle(View v);

        /** 微信好友 */
        void WeChatFriends(View v);

        /** QQ好友 */
        void QQFriends(View v);

        /** QQ空间 */
        void QQZone(View v);

        void WxMini(View v);
    }

}
